package proguide.library;

import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import android.util.Base64;

public class AESencrpypter
{

	private static final String		ALGO		= "AES";
	private static final byte[ ]	keyValue	= new byte[ ] { '|', '<', '@', '(', 'a', '[', '`', ']', '-', '<', '@', '*', '*', '!', ';', '&' };

	public static String encrypt( String Data )
	{
		try
		{
			Key key = generateKey( );
			Cipher c = Cipher.getInstance( ALGO );
			c.init( Cipher.ENCRYPT_MODE, key );
			byte[ ] encVal = c.doFinal( Data.getBytes( ) );
			String encryptedValue = Base64.encodeToString( encVal, Base64.DEFAULT );
			return encryptedValue;
		}
		catch ( Exception err )
		{
			return null;
		}
	}

	public static String decrypt( String encryptedData )
	{
		try
		{
			Key key = generateKey( );
			Cipher c = Cipher.getInstance( ALGO );
			c.init( Cipher.DECRYPT_MODE, key );
			byte[ ] decordedValue = Base64.decode( encryptedData, Base64.DEFAULT );
			byte[ ] decValue = c.doFinal( decordedValue );
			String decryptedValue = new String( decValue );
			return decryptedValue;
		}
		catch ( Exception err )
		{
			return null;
		}
	}

	private static Key generateKey( )
	{
		Key key = new SecretKeySpec( keyValue, ALGO );
		return key;
	}
}